package com.qianbei.common.base;


import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.widget.Toast;

import com.android.volley.ext.tools.HttpTools;
import com.android.volley.toolbox.Volley;
import com.qianbei.BuildConfig;
import com.qianbei.common.init.GlobalConfig;
import com.qianbei.common.init.SetData;
import com.qianbei.common.net.control.ServerControl;
import com.qianbei.common.net.okhttp.RequeastBean;
import com.qianbei.share.wx.WxShare;
import com.qianbei.user.unlogin.Unlogin;
//import com.tencent.bugly.crashreport.CrashReport;
import com.qianbei.view.HomeActivity;
import com.qianbei.view.binding.UnBingActivity;
import com.qianbei.view.orm.DaoMaster;
import com.qianbei.view.orm.DaoSession;
import com.speedata.libuhf.IUHFService;
import com.speedata.libuhf.UHFManager;
import com.tencent.bugly.Bugly;
import com.tencent.bugly.beta.Beta;
import com.tencent.bugly.crashreport.CrashReport;
import com.tencent.smtt.sdk.QbSdk;
import com.umeng.socialize.Config;
import com.umeng.socialize.PlatformConfig;
import com.umeng.socialize.UMShareAPI;

import java.util.ArrayList;
import java.util.Vector;

public class MyApplication extends BaseApplication {

    public static MyApplication mApplication;

    public static GlobalConfig gConfig;

    public static WxShare wxShare;

    public static boolean isBrowsLauch;

    public static IUHFService iuhfService;
    public static int setValue =10;//功率值默认10

    public static Vector<RequeastBean> netList = new Vector<>();//如果断网 缓存起来。

    private DaoMaster.DevOpenHelper helper = null;
    private SQLiteDatabase db;
    private DaoMaster daoMaster;

    public DaoSession daoSession;

    @Override
    public void onCreate() {
        super.onCreate();
//        CrashReport.initCrashReport(getApplicationContext());
        Beta.autoCheckUpgrade = true;
        Beta.canShowUpgradeActs.add(HomeActivity.class);
        Bugly.init(getApplicationContext(), "e204e768ee", true);
        Config.DEBUG = true;
//        UMShareAPI.get(this);

        //initX5Web();
        mApplication = this;
        HttpTools.init(this);
        ininConfig();
        //wxShare = WxShare.getInstent();

        ServerControl.setUnloginListener(new Unlogin());

        ServerControl.mQueue = Volley.newRequestQueue(BaseApplication.mApplication);

        try {
            if(iuhfService==null) {
                Log.d("gml", "MyApplication----------start");
                iuhfService = UHFManager.getUHFService(MyApplication.this);
                Log.d("gml", "MyApplication----------end");
                // do this once, for example in your Application class
                helper = new DaoMaster.DevOpenHelper(this, "gufei-db", null);
                db = helper.getWritableDatabase();
                daoMaster = new DaoMaster(db);
                daoSession = daoMaster.newSession();
            }
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(MyApplication.this, "模块不存在", Toast.LENGTH_SHORT).show();
        }
    }

    public DaoSession getDaoSession() {
        return daoSession;
    }

    private void initX5Web() {
        QbSdk.PreInitCallback cb = new QbSdk.PreInitCallback() {

            @Override
            public void onViewInitFinished(boolean arg0) {
                //x5內核初始化完成的回调，为true表示x5内核加载成功，否则表示x5内核加载失败，会自动切换到系统内核。
                Log.d("app", " onViewInitFinished is " + arg0);
            }

            @Override
            public void onCoreInitFinished() {
            }
        };
        //x5内核初始化接口
        QbSdk.initX5Environment(getApplicationContext(), cb);
    }

    {
        //微信 appid appsecret
//        PlatformConfig.setWeixin(BuildConfig.WE_CHAT_APP_ID, BuildConfig.WE_CHAT_APP_SECRET);
//        //QQ/空间
//        PlatformConfig.setQQZone("1106511996", "t2legEeE7niDBdjY");
//        //新浪微博 appkey appsecret
//        PlatformConfig.setSinaWeibo(BuildConfig.SINA_APP_KEY, BuildConfig.SINA_APP_SECRET, "");
    }

    private void ininConfig() {
        gConfig = GlobalConfig.getInstance();
        gConfig.userID = SetData.getUserID();
        gConfig.iconURl = SetData.getFace();
        gConfig.userName = SetData.getUserName();
        gConfig.phone = SetData.getUserPhone();
        gConfig.hxID = SetData.gethxID();
        gConfig.hxpass = SetData.gethxpass();
        gConfig.identity = SetData.getIdentity();
    }


}